package artid.com.arttogo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.ArtistRankingParser;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.view.CircleImageView;

/**
 * 
 *    
 * 项目名称：ArtworkArt   
 * 类名称：ArtistRanking_Adapter   
 * 类描述：艺术家排名适配器 
 * 创建人：耿卫斌   
 * 创建时间：2017-1-12 下午2:37:52   
 *
 */
public class ArtistRanking_Adapter extends BaseAdapter {
	private Context mContext;
	private List<ArtistRankingParser> list;

	public ArtistRanking_Adapter(Context mContext,
								 List<ArtistRankingParser> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_artistranking, null);
			holder.img=(CircleImageView) v.findViewById(R.id.item_artistranking_img);
			holder.ranking=(TextView) v.findViewById(R.id.item_artistranking_ranking);
			holder.name=(TextView) v.findViewById(R.id.item_artistranking_name);
			holder.worksNum=(TextView) v.findViewById(R.id.item_artistranking_worksNum);
			holder.followNum=(TextView) v.findViewById(R.id.item_artistranking_followNum);
			holder.describe=(TextView) v.findViewById(R.id.item_artistranking_describe);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		Glide.with(mContext).load(list.get(position).getImgurl()).asBitmap().centerCrop()
		.placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
		.into(new MyBitmapImageViewTarget(holder.img));
//		holder.img.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				Intent intent=new Intent(mContext,CollecterActivity.class);
//				intent.putExtra("name", list.get(position).getRealname());
//				intent.putExtra("id", list.get(position).getArtist_id());
//				mContext.startActivity(intent);
//			}
//		});
		int rankingNum=position+1;
		if(rankingNum==1){
			holder.ranking.setBackgroundResource(R.drawable.ysj_ico_numberone);
			holder.ranking.setText(rankingNum+"");
		}else if(rankingNum==2){
			holder.ranking.setBackgroundResource(R.drawable.ysj_ico_numbertwo);
			holder.ranking.setText(rankingNum+"");
		}else if(rankingNum==3){
			holder.ranking.setBackgroundResource(R.drawable.ysj_ico_numberthree);
			holder.ranking.setText(rankingNum+"");
		}else {
			holder.ranking.setBackgroundResource(R.drawable.ysj_ico_numbernor);
			holder.ranking.setText(rankingNum+"");
		}
		holder.name.setText(list.get(position).getRealname());
		holder.worksNum.setText(list.get(position).getArtnum()+"件作品");
		holder.followNum.setText(list.get(position).getFollownum()+"人关注");
		holder.describe.setText(list.get(position).getMemo());
		return v;
	}
	class ViewHolder {
		CircleImageView img;
		TextView ranking,name,worksNum,followNum,describe;
	}

}
